//
//  WebViewController.swift
//  BellManage
//
//  Created by Bestsch on 16/4/15.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class WebViewController: BaseViewController, UIWebViewDelegate {
    
    var webview: UIWebView!
    var activityIndicator: UIActivityIndicatorView!
    
    var url: String!
    var titleStr: String!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        self.title = titleStr
        
        webview = UIWebView.init(frame: CGRect(x: 0, y: 0, width: screenW, height: screenH))
        webview.delegate = self
        self.view.addSubview(webview)
        
        let request = URLRequest.init(url: URL.init(string: url)!)
        print("网页加载的地址" + url)
        webview.loadRequest(request)
    }
    
    /**
     开始加载
     
     - parameter webView:
     */
    func webViewDidStartLoad(_ webView: UIWebView) {
        
        let view = UIView.init(frame: CGRect(x: 0, y: 0, width: screenW, height: screenH))
        view.backgroundColor = UIColor.init(hexString: "f6f6f6", alpha: 1)
        view.alpha = 1
        view.tag = 108
        self.view.addSubview(view)
        
        activityIndicator = UIActivityIndicatorView.init(frame: CGRect(x: 0, y: 0, width: 32, height: 32))
        activityIndicator.center = view.center
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
        view.addSubview(activityIndicator)
        activityIndicator.startAnimating()
        
    }
    /**
     失败
     
     - parameter webView:
     - parameter error:   <#error description#>
     */
    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
        activityIndicator.stopAnimating()
        let view: UIView = self.view.viewWithTag(108)!
        view.removeFromSuperview()
    }
    /**
     完成
     
     - parameter webView: <#webView description#>
     */
    func webViewDidFinishLoad(_ webView: UIWebView) {
        activityIndicator.stopAnimating()
        let view: UIView = self.view.viewWithTag(108)!
        view.removeFromSuperview()
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */
    
}
